package ua.maxicash.util.criteria;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import ua.maxicash.util.Filter;
import ua.maxicash.util.JqgridQuery;

import java.util.List;

public class RestrictionsWrapper {
	
//		bw - begins with ( LIKE val% )
//		eq - equal ( = )
//		ne - not equal ( <> )
//		lt - little ( < )
//		le - little or equal ( <= )
//		gt - greater ( > )
//		ge - greater or equal ( >= )
//		ew - ends with (LIKE %val )
//		cn - contain (LIKE %val% )

	public static Criterion getCriterion(String op, String propertyName, Object value){
		
		if (op.equals("eq")) {
			return Restrictions.eq(propertyName, value);
		}
		
		if (op.equals("ne")) {
			return Restrictions.ne(propertyName, value);
		}
		
		if (op.equals("lt")) {
			return Restrictions.lt(propertyName, value);
		}
		
		if (op.equals("le")) {
			return Restrictions.le(propertyName, value);
		}
		
		if (op.equals("gt")) {
			return Restrictions.gt(propertyName, value);
		}
		
		if (op.equals("ge")) {
			return Restrictions.ge(propertyName, value);
		}
		
		if (op.equals("cn")) {
			return Restrictions.like(propertyName, "%"+value+"%");
		}
		
		if (op.equals("ew")) {
			return Restrictions.like(propertyName, "%"+value);
		}
		
		if (op.equals("bw")) {
			return Restrictions.like(propertyName, value+"%");
		}
		
		throw new UnsupportedOperationException(op + " is not supported");
		
	}
	
}
